package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlUser entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlUser
 * @author MyEclipse Persistence Tools
 */

public class MdlUserDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory.getLogger(MdlUserDAO.class);
	// property constants
	public static final String AUTH = "auth";
	public static final String CONFIRMED = "confirmed";
	public static final String POLICYAGREED = "policyagreed";
	public static final String DELETED = "deleted";
	public static final String SUSPENDED = "suspended";
	public static final String MNETHOSTID = "mnethostid";
	public static final String USERNAME = "username";
	public static final String PASSWORD = "password";
	public static final String IDNUMBER = "idnumber";
	public static final String FIRSTNAME = "firstname";
	public static final String LASTNAME = "lastname";
	public static final String EMAIL = "email";
	public static final String EMAILSTOP = "emailstop";
	public static final String ICQ = "icq";
	public static final String SKYPE = "skype";
	public static final String YAHOO = "yahoo";
	public static final String AIM = "aim";
	public static final String MSN = "msn";
	public static final String PHONE1 = "phone1";
	public static final String PHONE2 = "phone2";
	public static final String INSTITUTION = "institution";
	public static final String DEPARTMENT = "department";
	public static final String ADDRESS = "address";
	public static final String CITY = "city";
	public static final String COUNTRY = "country";
	public static final String LANG = "lang";
	public static final String THEME = "theme";
	public static final String TIMEZONE = "timezone";
	public static final String FIRSTACCESS = "firstaccess";
	public static final String LASTACCESS = "lastaccess";
	public static final String LASTLOGIN = "lastlogin";
	public static final String CURRENTLOGIN = "currentlogin";
	public static final String LASTIP = "lastip";
	public static final String SECRET = "secret";
	public static final String PICTURE = "picture";
	public static final String URL = "url";
	public static final String DESCRIPTION = "description";
	public static final String DESCRIPTIONFORMAT = "descriptionformat";
	public static final String MAILFORMAT = "mailformat";
	public static final String MAILDIGEST = "maildigest";
	public static final String MAILDISPLAY = "maildisplay";
	public static final String HTMLEDITOR = "htmleditor";
	public static final String AJAX = "ajax";
	public static final String AUTOSUBSCRIBE = "autosubscribe";
	public static final String TRACKFORUMS = "trackforums";
	public static final String TIMECREATED = "timecreated";
	public static final String TIMEMODIFIED = "timemodified";
	public static final String TRUSTBITMASK = "trustbitmask";
	public static final String IMAGEALT = "imagealt";
	public static final String SCREENREADER = "screenreader";

	public void save(MdlUser transientInstance) {
		log.debug("saving MdlUser instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlUser persistentInstance) {
		log.debug("deleting MdlUser instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlUser findById(java.lang.Long id) {
		log.debug("getting MdlUser instance with id: " + id);
		try {
			MdlUser instance = (MdlUser) getSession().get(
					"idv.loveloser.dao.MdlUser", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlUser instance) {
		log.debug("finding MdlUser instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlUser")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlUser instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from MdlUser as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByAuth(Object auth) {
		return findByProperty(AUTH, auth);
	}

	public List findByConfirmed(Object confirmed) {
		return findByProperty(CONFIRMED, confirmed);
	}

	public List findByPolicyagreed(Object policyagreed) {
		return findByProperty(POLICYAGREED, policyagreed);
	}

	public List findByDeleted(Object deleted) {
		return findByProperty(DELETED, deleted);
	}

	public List findBySuspended(Object suspended) {
		return findByProperty(SUSPENDED, suspended);
	}

	public List findByMnethostid(Object mnethostid) {
		return findByProperty(MNETHOSTID, mnethostid);
	}

	public List findByUsername(Object username) {
		return findByProperty(USERNAME, username);
	}

	public List findByPassword(Object password) {
		return findByProperty(PASSWORD, password);
	}

	public List findByIdnumber(Object idnumber) {
		return findByProperty(IDNUMBER, idnumber);
	}

	public List findByFirstname(Object firstname) {
		return findByProperty(FIRSTNAME, firstname);
	}

	public List findByLastname(Object lastname) {
		return findByProperty(LASTNAME, lastname);
	}

	public List findByEmail(Object email) {
		return findByProperty(EMAIL, email);
	}

	public List findByEmailstop(Object emailstop) {
		return findByProperty(EMAILSTOP, emailstop);
	}

	public List findByIcq(Object icq) {
		return findByProperty(ICQ, icq);
	}

	public List findBySkype(Object skype) {
		return findByProperty(SKYPE, skype);
	}

	public List findByYahoo(Object yahoo) {
		return findByProperty(YAHOO, yahoo);
	}

	public List findByAim(Object aim) {
		return findByProperty(AIM, aim);
	}

	public List findByMsn(Object msn) {
		return findByProperty(MSN, msn);
	}

	public List findByPhone1(Object phone1) {
		return findByProperty(PHONE1, phone1);
	}

	public List findByPhone2(Object phone2) {
		return findByProperty(PHONE2, phone2);
	}

	public List findByInstitution(Object institution) {
		return findByProperty(INSTITUTION, institution);
	}

	public List findByDepartment(Object department) {
		return findByProperty(DEPARTMENT, department);
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByCity(Object city) {
		return findByProperty(CITY, city);
	}

	public List findByCountry(Object country) {
		return findByProperty(COUNTRY, country);
	}

	public List findByLang(Object lang) {
		return findByProperty(LANG, lang);
	}

	public List findByTheme(Object theme) {
		return findByProperty(THEME, theme);
	}

	public List findByTimezone(Object timezone) {
		return findByProperty(TIMEZONE, timezone);
	}

	public List findByFirstaccess(Object firstaccess) {
		return findByProperty(FIRSTACCESS, firstaccess);
	}

	public List findByLastaccess(Object lastaccess) {
		return findByProperty(LASTACCESS, lastaccess);
	}

	public List findByLastlogin(Object lastlogin) {
		return findByProperty(LASTLOGIN, lastlogin);
	}

	public List findByCurrentlogin(Object currentlogin) {
		return findByProperty(CURRENTLOGIN, currentlogin);
	}

	public List findByLastip(Object lastip) {
		return findByProperty(LASTIP, lastip);
	}

	public List findBySecret(Object secret) {
		return findByProperty(SECRET, secret);
	}

	public List findByPicture(Object picture) {
		return findByProperty(PICTURE, picture);
	}

	public List findByUrl(Object url) {
		return findByProperty(URL, url);
	}

	public List findByDescription(Object description) {
		return findByProperty(DESCRIPTION, description);
	}

	public List findByDescriptionformat(Object descriptionformat) {
		return findByProperty(DESCRIPTIONFORMAT, descriptionformat);
	}

	public List findByMailformat(Object mailformat) {
		return findByProperty(MAILFORMAT, mailformat);
	}

	public List findByMaildigest(Object maildigest) {
		return findByProperty(MAILDIGEST, maildigest);
	}

	public List findByMaildisplay(Object maildisplay) {
		return findByProperty(MAILDISPLAY, maildisplay);
	}

	public List findByHtmleditor(Object htmleditor) {
		return findByProperty(HTMLEDITOR, htmleditor);
	}

	public List findByAjax(Object ajax) {
		return findByProperty(AJAX, ajax);
	}

	public List findByAutosubscribe(Object autosubscribe) {
		return findByProperty(AUTOSUBSCRIBE, autosubscribe);
	}

	public List findByTrackforums(Object trackforums) {
		return findByProperty(TRACKFORUMS, trackforums);
	}

	public List findByTimecreated(Object timecreated) {
		return findByProperty(TIMECREATED, timecreated);
	}

	public List findByTimemodified(Object timemodified) {
		return findByProperty(TIMEMODIFIED, timemodified);
	}

	public List findByTrustbitmask(Object trustbitmask) {
		return findByProperty(TRUSTBITMASK, trustbitmask);
	}

	public List findByImagealt(Object imagealt) {
		return findByProperty(IMAGEALT, imagealt);
	}

	public List findByScreenreader(Object screenreader) {
		return findByProperty(SCREENREADER, screenreader);
	}

	public List findAll() {
		log.debug("finding all MdlUser instances");
		try {
			String queryString = "from MdlUser";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlUser merge(MdlUser detachedInstance) {
		log.debug("merging MdlUser instance");
		try {
			MdlUser result = (MdlUser) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlUser instance) {
		log.debug("attaching dirty MdlUser instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlUser instance) {
		log.debug("attaching clean MdlUser instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}